<?php
/**
 * MMS Class
 *
 */
class MMS extends MyObject {

	protected $files;
	protected $subject;
	protected $from;
	
	public function __construct() {
		
		parent::__construct();
		
		$this->files = array();
	}
	
	public function getData($dir = './') {
		
		$this->files = array();
		$time = time();
		$count = 0;
		
		// subject
		$this->subject = strtolower(substr(strstr($_POST['subject']," "), 1));
		$this->from = $_POST['from'];
		
		foreach($_FILES as $key){
			
			$file = array();
			$file['name'] = '';		// filename
			$file['content'] = '';	// file content (text)
			$file['type'] = '';		// media type (text, image, audio, video)
			
			$newname = $time.'_'.$count.strrchr($key['name'], '.');
			
			move_uploaded_file($key['tmp_name'], $dir.$newname); 
			chmod($dir.$newname, 0777);
			
			$file['name'] = $newname;
			   
			if (preg_match("/text/i", $key['type'])) {
				$file['type'] = 'text';
				$file['content'] = file_get_contents($dir.$newname);
			}
			elseif (preg_match("/image/i", $key['type']))
				$file['type'] = "image";
			elseif (preg_match("/audio/i", $key['type']))
				$file['type'] = "audio";
			elseif (preg_match("/video/i", $key['type']))
				$file['type'] = "video";
			else
				$file['type'] = "undefined";
				
			$this->files[] = $file;
			$count++;
		}
	}
}
?>
